package liquidfs.ui.web;

import java.io.*;
import java.util.*;

import liquidfs.*;
import liquidfs.core.*;
import liquidfs.data.*;

import com.sun.net.httpserver.*;
import com.thoughtworks.xstream.annotations.*;

public class QueuesHandler implements HttpHandler {

   private Application app;
   private Serializer serializer;
   
   public QueuesHandler (Application app) {
      this.app = app;
      this.serializer = Serializer.getPlainSerializer(app);
      this.serializer.preprocess(QueuesList.class);
   }
   
   @Override
   public void handle(HttpExchange exchange) throws IOException {
      
      exchange.sendResponseHeaders(200, 0);
      serializer.serialize(new QueuesList(app.getOperationProcessor().getQueues()), exchange.getResponseBody());
      exchange.close();
   }
   
   @XStreamAlias("queues")
   private static class QueuesList {
      
      @XStreamImplicit()
      public List<OperationQueue> queues;
      public QueuesList(List<OperationQueue> list) {
         this.queues = list;
      }
   }

}
